package com.weng.platform.apiManager.doc.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.weng.framework.core.model.ResponseData;
import com.weng.framework.dao.mybatis.model.page.PageModel;
import com.weng.framework.dao.mybatis.service.BaseServiceImpl;
import com.weng.platform.apiManager.doc.entity.DocLock;
import com.weng.platform.apiManager.doc.mapper.DocLockMapper;
import com.weng.platform.apiManager.doc.service.IDocLockService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.Arrays;


/**
 * 文档编辑锁 服务实现类
 *
 * @author wengzhonghui
 * @date 2020-09-25 18:40:12
 *
 */ 
@Slf4j
@Service
public class DocLockServiceImpl extends BaseServiceImpl<DocLockMapper, DocLock> implements IDocLockService {
	@Autowired
	private DocLockMapper docLockMapper;
	

	/**
	 * 分页查询文档编辑锁
	 * @return
	 */
	@Override
	public IPage<DocLock> list(Integer pageNo,Integer pageSize) {
		QueryWrapper<DocLock> qw = new QueryWrapper<>();
		IPage<DocLock> page = new PageModel<>(pageNo,pageSize);
		return docLockMapper.selectPage(page,qw);
	}


	/**
	 * 获取单个文档编辑锁
	 * @param id
	 * @return
	 */
	@Override
	public DocLock getById(Serializable id) {
		return super.getById(id);
	}

	/**
	 * 新增单个文档编辑锁
	 * @param docLock
	 * @return
	 */
	@Override
	public DocLock add(DocLock docLock)  {
		
		docLockMapper.insert(docLock);
		return docLock;
	}

	/**
	 * 更新单个文档编辑锁
	 * @param docLock
	 * @return
	 * @
	 */
	@Override
	public int update(DocLock docLock)  {
		
		return docLockMapper.updateById(docLock);

	}


	@Override
	public ResponseData removeByIds(String ids) {
		String[] docLockIds = ids.split(",");
		boolean flag = this.removeByIds(Arrays.asList(docLockIds));
		if (flag) {
			return ResponseData.success();
		} else {
			return ResponseData.success();
		}
	}

}
